<?php

namespace App\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;

class CreateRoomRequest extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     */
    public function authorize(): bool
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     */
    public function rules(): array
    {
        return [
            'title' => 'required|string|max:100',
            'type' => 'required|in:temporary,permanent',
            'menuSource' => 'sometimes|in:default,custom',
            'menuId' => 'sometimes|exists:menus,id',
            'settings' => 'sometimes|array',
            'settings.allowParticipantAdd' => 'sometimes|boolean',
            'settings.allowParticipantSuggest' => 'sometimes|boolean',
            'settings.showUserFavorites' => 'sometimes|boolean',
        ];
    }

    /**
     * Get custom messages for validator errors.
     */
    public function messages(): array
    {
        return [
            'title.required' => '房间标题不能为空',
            'title.max' => '房间标题不能超过100个字符',
            'type.required' => '房间类型不能为空',
            'type.in' => '房间类型必须是temporary或permanent',
            'menuSource.in' => '菜单来源必须是default或custom',
            'menuId.exists' => '菜单不存在',
        ];
    }
}
